﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;

namespace BAL
{
    public class BooksManager
    {
        public IQueryable<Object> getAllBooks()
        {
            LibraryEntities le = new LibraryEntities();
            var books = from bookItem in le.Books
                        select new
                        {
                            bookItem.Title,
                            bookItem.Author
                        };
            return books;
        }

        public IQueryable<Object> getAllBooksTitleByDesc()
        {
            LibraryEntities le = new LibraryEntities();
            var books = from bookItem in le.Books
                       
                        orderby bookItem.Title descending 
                        select new
                        {
                            bookItem.Title,
                            bookItem.Author
                        };
            return books;
        }

        public IQueryable<Object> getAllBooksTitleByAsc()
        {
            LibraryEntities le = new LibraryEntities();
            var books = from bookItem in le.Books
                 
                        orderby bookItem.Title ascending 
                        select new
                        {
                            bookItem.Title,
                            bookItem.Author
                        };
            return books;
        }

        public IQueryable<Object> getAllBooksAuthorByDesc()
        {
            LibraryEntities le = new LibraryEntities();
            var books = from bookItem in le.Books
                    
                        orderby bookItem.Author descending
                        select new
                        {
                            bookItem.Title,
                            bookItem.Author
                        };
            return books;
        }

        public IQueryable<Object> getAllBooksAuthorByAsc()
        {
            LibraryEntities le = new LibraryEntities();
            var books = from bookItem in le.Books
                     
                        orderby bookItem.Author ascending 
                        select new
                        {
                            bookItem.Title,
                            bookItem.Author
                        };
            return books;
        }

        public IQueryable<Object> getAllAvailableBooks()
        {
            LibraryEntities le = new LibraryEntities();
            var books = from bookItem in le.Books
                        where bookItem.Availability == true
                        orderby bookItem.Author ascending                   
                        select new
                        {
                            bookItem.Title,
                            bookItem.Author
                        };
            return books;
        }

        public IQueryable<Object> getAllTakenBooks()
        {
            LibraryEntities le = new LibraryEntities();
            var books = from bookItem in le.Books
                        where bookItem.Availability == false
                        orderby bookItem.Author ascending
                        select new
                        {
                            bookItem.Title,
                            bookItem.Author
                        };
            return books;
        }    

    }
}
